EXEC := invaders

DIRSRC := src
DIROBJ := obj
DIRHEA := src

CXX := g++

# Flags de compilación -----------------------------------------------
CXXFLAGS := -I $(DIRHEA) -Wall `pkg-config --cflags OGRE` 

# Flags del linker ---------------------------------------------------
LDFLAGS := `pkg-config --libs-only-L OGRE`
LDLIBS := `pkg-config --libs-only-l OGRE` -lOIS -lGL -lstdc++

# Modo de compilación (-mode=release -mode=debug) --------------------
ifeq ($(mode), release) 
	CXXFLAGS += -O2 -D_RELEASE
else 
	CXXFLAGS += -D_DEBUG
	mode := debug
endif

# Obtención automática de la lista de objetos a compilar -------------
OBJS := $(subst $(DIRSRC), $(DIROBJ), \
	$(patsubst %.cpp, %.o, $(wildcard $(DIRSRC)/*.cpp)))

.PHONY: all dirs clean

all: dirs $(EXEC)

dirs:
	if [ ! -d $(DIROBJ) ]; then mkdir $(DIROBJ); fi;

# Enlazado -----------------------------------------------------------
$(EXEC): $(OBJS)
	$(CXX) $(LDFLAGS) -o $@ $^ $(LDLIBS)

# Compilación --------------------------------------------------------
$(DIROBJ)/%.o: $(DIRSRC)/%.cpp
	$(CXX) $(CXXFLAGS) -c $< -o $@ $(LDLIBS)

# Limpieza de temporales ---------------------------------------------
clean:
	rm -rf *.log $(EXEC) *~ $(DIROBJ) $(DIRSRC)/*~

cleanE:
	rm -rf *.log *~ $(DIROBJ) $(DIRSRC)/*~
